<template>
  <div>
      <el-form :model="formData" ref="formData" label-width="130px">
        <fieldset class="contain-box">
          <legend class="contain-title">重新核实资费</legend>
          <el-row>
            <el-col :span="12" :offset="1">
              <el-form-item  label="重新核实资费原因:"    prop="reAmountCause"  >
                <el-input
                  type="textarea"
                  :rows="2"
                  placeholder="请输入内容"
                  v-model="formData.reason"  >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <br/>
          <el-row class="radioBtn">
            <el-col :span="12" :offset="1">
              <el-radio-group v-model="taskVal"   >
                <el-radio :label="1">重新核实两端费用</el-radio>
                <el-radio :label="2">重新核实甲端费用</el-radio>
                <el-radio :label="3">重新核实乙端费用</el-radio>
              </el-radio-group>
            </el-col>
          </el-row>
        </fieldset>   
      </el-form>
      <div class="text-c">
          <el-button type="info" @click="closeDialog">取 消</el-button>
          <el-button type="primary" @click="submitData" >确 定</el-button>
      </div>
    </div>

</template>

<script>
import requestUtil from '@/utils/requestEnc';
import OrderService from "@/api/order/OrderService";

export default {
    components: {
		requestUtil,
	 
  },
  props:{
	  	ODKInfo: {
			type: Object,
			default: () => {
				return {};
			},
		},
		CTOInfo: {
			type: Array,
			default: () => {
				return [];
			},
		},

  },
  data() {
    return {
      formData: {},
      taskVal:'',
    };
  },
 

  mounted() {
    
    

  },

  methods: {
    closeDialog(){
      this.$emit('update:show',false);

    },
    async submitData(){
      
      if(this.formData.reason == '' || this.formData.reason == null || this.formData.reason==undefined){
          this.$alert("请输入重新核实资费原因!", "警告", {
            type: "warning",
            confirmButtonText: "关闭",
          });
          return false;
      }

      if(this.taskVal=='' || this.taskVal==null || this.taskVal==undefined){
          this.$alert("请选择需要重新核实的费用!", "警告", {
            type: "warning",
            confirmButtonText: "关闭",
          });
          return false;
      }else{

        var orderItemId = this.CTOInfo[0].orderItemId;// this.CTOInfo[0].orderItemId;
        var custId = this.CTOInfo[0].custId;//this.CTOInfo[0].custId;
        var typeId = this.taskVal;
        var reason = this.formData.reason;
        var prodId = this.CTOInfo[0].prodId;
        var taskId = '';

        //IP虚拟专网的甲乙端核实资费的任务id不一样
        if("80007005"==prodId||"80007006"==prodId||"80007007"==prodId){
          if(typeId=='2'){//CE核实资费
            taskId = 'TACHE00050017';
          }
          if(typeId=='3'){//PE核实资费
            taskId = 'TACHE00050018';
          }
          if(typeId=='5'){//填报A端业务月租费
            taskId = 'TACHE00050003';
          }
        }else{
          if(typeId=='0'){//表示国际业务的重新核实资费
            taskId = 'TACHE10100001';
          }
          if(typeId=='1'){
            taskId = "TACHE00050001,TACHE00050002";
          }
          if(typeId=='2'){
            taskId = 'TACHE00050001';
          }
          if(typeId=='3'){
            taskId = 'TACHE00050002';
          }
          if(typeId=='5'){
            taskId = 'TACHE00050003';
          }
          if(typeId=='9'){
            taskId = 'TACHE00050011';
          }
          if(typeId=='10'){
            taskId ='TACHE10520001';
          }
        }
        var taskIds = taskId;
        const res =await OrderService.reTariffOrder({orderItemId,taskIds,typeId,reason,custId,prodId});
        
        
        //中台执行成功调流程
        if(res.meta.resultCode=="0"){
          let params = {
            interFaceType: "ORDER",
            sqlId: 2021072801,
            paramStr: "orderItemId:"+orderItemId,
          };
          
          //取得流程实例ID
          const resultItem =await OrderService.getCustNum(params);
          var processInstanceId=resultItem.meta.resList.executeSqlResps[0].flow_inst_id;
          var custSoNumber = this.CTOInfo[0].custSoNumber; //流水号

          // 流程调用taskId只能传一个，所以typeId='1'时直接调两次
          if( typeId=='1'){
            taskId="TACHE00050001";
            const results =await OrderService.reTariffInterface({taskId,custSoNumber,processInstanceId,custId});
         
            // 第一个taskID调用成功后再调用第二个
            if(results.code == "0"){
              

              taskId="TACHE00050002";
              const resQ =await OrderService.reTariffInterface({taskId,custSoNumber,processInstanceId,custId}); 
              if(resQ.code == "0"){
                this.$emit('update:show',false);
              }else{
                this.$alert("流程调用失败,请重试!", "警告", {
                  type: "warning",
                  confirmButtonText: "关闭",
                });
                return false;   
              }
            }else{
                

                this.$alert("流程调用失败,请重试!", "警告", {
                type: "warning",
                confirmButtonText: "关闭",
                });
                return false;
            }
            
          }else{
            const res2 =await OrderService.reTariffInterface({taskId,custSoNumber,processInstanceId,custId});
         
             // 流程调用成功关闭页面,无返回
            if(res2.code == "0"){
                this.$emit('update:show',false);
            }else{
              this.$alert("流程调用失败,请重试!", "警告", {
                type: "warning",
                confirmButtonText: "关闭",
              });
              return false;
            }
          }
         }else{
          this.$alert(res.meta.resultMsg, "警告", {
              type: "warning",
              confirmButtonText: "关闭",
            });
            return false;
        }
      }
    }
    },
 


};
</script>
<style lang='scss' scoped>
.contain-box {
  padding: 0.2rem;
  border: 1px solid #f56f3c;
}
.contain-title {
  margin-left: 0.4rem;
  padding: 0 0.1rem;
}
.radioBtn {
  padding-left: 0.2rem;
}
.text-c{
  text-align:center;
  margin-top:30px;
}
</style>